import React, { Component } from 'react';
import order from './order.module.scss'
import membertop from '../../static/membertop.png'
import {Link} from 'react-router-dom'
import {divide} from '../../utils/maths'
import {formatTime,getUrlParam} from '../../utils/tools'
import {getMemberCardOrders} from '../../utils/interface'
class OrderInfo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            mockList: [
                
            ],
           
        }
    }
    render() {
        return (
            <div>
            {this.state.mockList.map((item, index) => (
                <div className={order.content} key={index}>
                    <div className={order.tag} onClick={this.bindSwitch.bind(this, index)}>
                        <p>{item.month}</p>
                        <img src={membertop} style={{ transform: item.h ? 'rotate(0deg)' : 'rotate(180deg)' }} alt="" />
                    </div>
                    <div className={order.list} style={{ height: item.h ? 0 : item.data.length * 1.68 + 'rem' }}>
                        {item.data.map((item, idx) => (
                            <div className={order.item} key={idx}>
                                <Link to={`/info?orderNumber=${item.orderNumber}`}>
                                    <div>
                                        <p>{item.productInfoName}{item.productName} {item.storeName}</p>
                                        <p>￥{divide(item.amount,100)}</p>
                                    </div>
                                    <p>{formatTime(new Date(item.createTime), '-')}</p>
                                </Link>
                            </div>
                        ))}
                    </div>
                </div>
            ))}
                </div>
        );
    }
   
    bindSwitch(index) {
        this.state.mockList[index].h = !this.state.mockList[index].h
        this.setState({
            mockList: this.state.mockList
        })
    }
    componentDidMount() {
        this.getMemberCardOrders()
    }
    getMemberCardOrders(){
        let m2;
        if(getUrlParam('mouth')){
            let m = getUrlParam('mouth').split('-')
            m2 = m[0]+m[1]
        }
        
        getMemberCardOrders({month:m2?m2:"",page:1,pageSize:999999,memberCardId:getUrlParam('sid')}).then(res=>{
            console.log(res.data.result)
            this.setState({
                mockList:res.data.result
            })
        })
    }
   
}

export default OrderInfo;